package com.lanou.renrenxin.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.lanou.renrenxin.R;
import com.lanou.renrenxin.adapter.PrivicyAdapter;
import com.lanou.renrenxin.base.BaseActivity;
import com.lanou.renrenxin.dao.Pricicy;
import com.lanou.renrenxin.dao.PricicyDao;

import java.util.List;

/**
 * Created by zy on 16/3/23.
 * 私密聊联系人界面
 */
public class DetailPrivicyActivity extends BaseActivity implements View.OnClickListener {
    private Button btnBack, btnCreat;
    private TextView textViewPrivity;
    private List<Pricicy> pricicies;
    private PricicyDao pricicyDao ;
    private PrivicyAdapter privicyAdapter;
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detailprivicy);
        initView();
        setUp();
    }


    private void initView() {
        btnBack = (Button) findViewById(R.id.btnBack);
        btnCreat = (Button) findViewById(R.id.btnCreat);
        textViewPrivity = (TextView) findViewById(R.id.txtTitle);
        listView = (ListView) findViewById(R.id.pricivy_listview);
    }

    private void setUp() {
        btnBack.setVisibility(View.VISIBLE);
        btnBack.setOnClickListener(this);
        btnCreat.setVisibility(View.GONE);
        textViewPrivity.setText("私密聊");
        pricicies = getData();
        privicyAdapter = new PrivicyAdapter(pricicies,this);
        listView.setAdapter(privicyAdapter);
    }

    //取数据库
    private List<Pricicy> getData() {
        if (pricicyDao != null) {
            return pricicyDao.queryBuilder().list();
        } else {
            return null;
        }
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnBack:
                finish();
                break;
        }
    }
}
